import { createStore } from 'vuex'
import cookies from 'vue-cookies'

export default createStore({
  state: {
    articleInfo : [],
    webPathPrefix : "",
    backgroundPosition : {
      left : '0px',
      top : '0px'
    }
    
  },
  getters: {
    token : () => {
      return cookies.get("token");
    },
    getPathPrefix : (state) => () => {
      var preifix = process.env.NODE_ENV == "development" ? "api/" : "server/";
      return preifix + state.webPathPrefix;
    },
    loginStatus : function() {
      return window.sessionStorage.getItem("LoginStatus");
    },
  },
  mutations: {
    setToken(state,val) {
      cookies.set("token" , val);
    },
    setLoginStatus(state,status) {
      if(status == true || status == false) window.sessionStorage.setItem("LoginStatus",status);
    },
    setBackgroundTop(state,val) {
      state.backgroundPosition.top = val + 'px';
    },
    setBackgroundLeft(state,val) {
      state.backgroundPosition.left = val + 'px';
    },
    setArticleInfo(state,val) {
      state.articleInfo = val;
    }
  },
  actions: {
    
  },
  modules: {
  }
})
